//
//  TitleTableViewCell.m
//  Miss
//
//  Created by Alan on 15/1/28.
//  Copyright (c) 2015年 Alan. All rights reserved.
//

#import "TitleTableViewCell.h"

@interface TitleTableViewCell()
- (void)setTitle_picView;

@end

@implementation TitleTableViewCell
- (void)dealloc
{
    [_date release];
    [_dateLine release];
    [_titleLine release];
    [_picLaber release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setTitle_picView];
    }
    return self;
}
//布局
- (void)setTitle_picView
{
    self.date = [[UIImageView alloc]init];
    //定义(设置当前星期)
    NSDate *date = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comps;
    //获得周几
    comps = [calendar components:(NSCalendarUnitWeekday) fromDate:date];
    NSInteger weekday = [comps weekday];//星期几
    
    NSLog(@"weekday:%ld",weekday);//比当前多一天
    //设置每天显示当前星期
    if(weekday == 1){
        [_date setImage:[UIImage imageNamed:@"Sunday.jpg"]];
    }else if(weekday == 2){
        [_date setImage:[UIImage imageNamed:@"Saturday.jpg"]];
    }else if(weekday == 3){
        [_date setImage:[UIImage imageNamed:@"Tuesday.jpg"]];
    }else if(weekday == 4){
        [_date setImage:[UIImage imageNamed:@"Wednesday.jpg"]];
    }else if(weekday == 5){
        [_date setImage:[UIImage imageNamed:@"Thursday.jpg"]];
    }else if(weekday == 6){
        [_date setImage:[UIImage imageNamed:@"Friday.jpg"]];
    }else if(weekday == 7){
        [_date setImage:[UIImage imageNamed:@"Saturday.jpg"]];
    }
    [self.contentView addSubview :self.date];
    [_date release];
    //日期下的横线
    self.dateLine = [[UIImageView alloc]init];
    [_dateLine setImage:[UIImage imageNamed:@"Titilelay.png"]];
    [self.contentView addSubview:self.dateLine];
    [_dateLine release];
    //图片
    self.titleLine = [[UIImageView alloc]init];
    self.titleLine.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.titleLine];
    [_titleLine release];
    //图片作者及信息
    self.picLaber = [[UILabel alloc]init];
    self.picLaber.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.picLaber];
    [_picLaber release];
}

-(void)layoutSubviews
{
    self.date.frame = CGRectMake(5, 0, 100, 35);
    self.dateLine.frame = CGRectMake(14, 28, 350, 1);
    self.titleLine.center = CGPointMake(self.contentView.frame.size.width/2, 190);
    self.titleLine.bounds = CGRectMake(0, 0, 340, 300);
    self.picLaber.frame = CGRectMake(268, 360, 90, 30);
    [super layoutSubviews];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
